"""
GitCode API错误处理
"""

class GitCodeAPIError(Exception):
    """GitCode API错误基类"""
    def __init__(self, status_code: int, message: str):
        self.status_code = status_code
        self.message = message
        super().__init__(f"API错误 ({status_code}): {message}")


class GitCodeAuthError(GitCodeAPIError):
    """认证错误"""
    def __init__(self, message: str = "认证失败"):
        super().__init__(401, message)


class GitCodeNotFoundError(GitCodeAPIError):
    """资源不存在错误"""
    def __init__(self, resource_type: str, resource_id: str):
        message = f"{resource_type} '{resource_id}' 不存在"
        super().__init__(404, message)


class GitCodePermissionError(GitCodeAPIError):
    """权限错误"""
    def __init__(self, message: str = "没有足够权限执行该操作"):
        super().__init__(403, message)


class GitCodeRateLimitError(GitCodeAPIError):
    """API速率限制错误"""
    def __init__(self, message: str = "超过API调用频率限制"):
        super().__init__(429, message)


class GitCodeServerError(GitCodeAPIError):
    """服务器错误"""
    def __init__(self, status_code: int = 500, message: str = "服务器错误"):
        super().__init__(status_code, message)


class GitCodeValidationError(GitCodeAPIError):
    """请求验证错误"""
    def __init__(self, message: str = "请求参数验证失败"):
        super().__init__(422, message) 